﻿namespace HRM.CORE
{
    using DevExpress.Data;
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms; using Common;
    using DevExpress.XtraGrid.Views.Base;

    public class xucActivity : UserControl
    {
        private BarDockControl barDockControlBottom;
        private BarDockControl barDockControlLeft;
        private BarDockControl barDockControlRight;
        private BarDockControl barDockControlTop;
        private BarManager barManager1;
        private BarButtonItem bbiDelete;
        private GridColumn colActivity;
        private GridColumn colDescription;
        private GridColumn colEmployeeCode;
        private GridColumn colFromDate;
        private GridColumn colPosition;
        private GridColumn colToDate;
        private GridColumn colWhere;
        private IContainer components;
        private GridView gbList;
        private GridControl gcList;
        private GridColumn gridColumn1;
        private string m_EmployeeCode;
        private PopupMenu ppMenu;

        public xucActivity()
        {
            this.components = null;
            this.m_EmployeeCode = "";
            this.InitializeComponent();
        }

        public xucActivity(string EmployeeCode)
        {
            this.components = null;
            this.m_EmployeeCode = "";
            this.InitializeComponent();
            this.m_EmployeeCode = EmployeeCode;
        }

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.gbList.DeleteSelectedRows();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void gbList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                this.gbList.DeleteSelectedRows();
            }
            if (e.KeyCode == Keys.F5)
            {
                this.Init();
            }
            if (e.KeyCode == Keys.Escape)
            {
                this.gbList.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
            }
        }

        public void Init()
        {
            this.barManager1.SetPopupContextMenu(this.gcList, this.ppMenu);
            this.gcList.DataSource = new HRM_EMPLOYEE_ACTIVITY().GetList(this.m_EmployeeCode);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.gcList = new GridControl();
            this.gbList = new GridView();
            this.colEmployeeCode = new GridColumn();
            this.colFromDate = new GridColumn();
            this.colToDate = new GridColumn();
            this.colActivity = new GridColumn();
            this.colWhere = new GridColumn();
            this.colPosition = new GridColumn();
            this.colDescription = new GridColumn();
            this.gridColumn1 = new GridColumn();
            this.barManager1 = new BarManager(this.components);
            this.barDockControlTop = new BarDockControl();
            this.barDockControlBottom = new BarDockControl();
            this.barDockControlLeft = new BarDockControl();
            this.barDockControlRight = new BarDockControl();
            this.bbiDelete = new BarButtonItem();
            this.ppMenu = new PopupMenu(this.components);
            this.gcList.BeginInit();
            this.gbList.BeginInit();
            this.barManager1.BeginInit();
            this.ppMenu.BeginInit();
            base.SuspendLayout();
            this.gcList.Dock = DockStyle.Fill;
            this.gcList.EmbeddedNavigator.Buttons.Append.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Remove.Visible = false;
            this.gcList.EmbeddedNavigator.TextStringFormat = "{0}/{1}";
            this.gcList.Location = new Point(0, 0);
            this.gcList.MainView = this.gbList;
            this.gcList.Name = "gcList";
            this.gcList.Size = new Size(0x30b, 0x1de);
            this.gcList.TabIndex = 5;
            this.gcList.UseEmbeddedNavigator = true;
            this.gcList.ViewCollection.AddRange(new BaseView[] { this.gbList });
            this.gbList.Appearance.GroupRow.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.gbList.Appearance.GroupRow.Options.UseFont = true;
            this.gbList.Appearance.HeaderPanel.Options.UseTextOptions = true;
            this.gbList.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
            this.gbList.Appearance.HeaderPanel.TextOptions.WordWrap = WordWrap.Wrap;
            this.gbList.Appearance.Row.Options.UseTextOptions = true;
            this.gbList.Appearance.Row.TextOptions.WordWrap = WordWrap.Wrap;
            this.gbList.BorderStyle = BorderStyles.NoBorder;
            this.gbList.ColumnPanelRowHeight = 0x24;
            this.gbList.Columns.AddRange(new GridColumn[] { this.colEmployeeCode, this.colFromDate, this.colToDate, this.colActivity, this.colWhere, this.colPosition, this.colDescription });
            this.gbList.GridControl = this.gcList;
            this.gbList.GroupPanelText = "K\x00e9o v\x00e0 Thả cột v\x00e0o đ\x00e2y để nh\x00f3m dữ liệu";
            this.gbList.IndicatorWidth = 40;
            this.gbList.Name = "gbList";
            this.gbList.OptionsBehavior.AllowIncrementalSearch = true;
            this.gbList.OptionsBehavior.AutoExpandAllGroups = true;
            this.gbList.OptionsBehavior.CopyToClipboardWithColumnHeaders = false;
            this.gbList.OptionsBehavior.FocusLeaveOnTab = true;
            this.gbList.OptionsLayout.StoreAllOptions = true;
            this.gbList.OptionsLayout.StoreAppearance = true;
            this.gbList.OptionsMenu.EnableColumnMenu = false;
            this.gbList.OptionsMenu.EnableGroupPanelMenu = false;
            this.gbList.OptionsNavigation.EnterMoveNextColumn = true;
            this.gbList.OptionsSelection.InvertSelection = true;
            this.gbList.OptionsSelection.MultiSelect = true;
            this.gbList.OptionsView.ColumnAutoWidth = false;
            this.gbList.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
            this.gbList.OptionsView.RowAutoHeight = true;
            this.gbList.OptionsView.ShowAutoFilterRow = true;
            this.gbList.OptionsView.ShowGroupPanel = false;
            this.gbList.SortInfo.AddRange(new GridColumnSortInfo[] { new GridColumnSortInfo(this.colFromDate, ColumnSortOrder.Ascending) });
            this.gbList.KeyDown += new KeyEventHandler(this.gbList_KeyDown);
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colFromDate.Caption = "Từ ng\x00e0y";
            this.colFromDate.FieldName = "FromDate";
            this.colFromDate.Name = "colFromDate";
            this.colFromDate.Visible = true;
            this.colFromDate.VisibleIndex = 0;
            this.colFromDate.Width = 0x5b;
            this.colToDate.Caption = "Đến ng\x00e0y";
            this.colToDate.FieldName = "ToDate";
            this.colToDate.Name = "colToDate";
            this.colToDate.Visible = true;
            this.colToDate.VisibleIndex = 1;
            this.colToDate.Width = 0x54;
            this.colActivity.Caption = "L\x00e0m c\x00f4ng t\x00e1c g\x00ec";
            this.colActivity.FieldName = "Activity";
            this.colActivity.Name = "colActivity";
            this.colActivity.Visible = true;
            this.colActivity.VisibleIndex = 2;
            this.colActivity.Width = 220;
            this.colWhere.Caption = "Ở đ\x00e2u";
            this.colWhere.FieldName = "Where";
            this.colWhere.Name = "colWhere";
            this.colWhere.Visible = true;
            this.colWhere.VisibleIndex = 3;
            this.colWhere.Width = 0x98;
            this.colPosition.Caption = "Giữ chức vụ g\x00ec";
            this.colPosition.FieldName = "Position";
            this.colPosition.Name = "colPosition";
            this.colPosition.Visible = true;
            this.colPosition.VisibleIndex = 4;
            this.colPosition.Width = 0x67;
            this.colDescription.Caption = "M\x00f4 tả";
            this.colDescription.FieldName = "Description";
            this.colDescription.Name = "colDescription";
            this.colDescription.Visible = true;
            this.colDescription.VisibleIndex = 5;
            this.colDescription.Width = 0x12b;
            this.gridColumn1.Caption = "Mối quan hệ";
            this.gridColumn1.FieldName = "RelativeName";
            this.gridColumn1.Name = "gridColumn1";
            this.gridColumn1.Visible = true;
            this.gridColumn1.VisibleIndex = 0;
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Items.AddRange(new BarItem[] { this.bbiDelete });
            this.barManager1.MaxItemId = 1;
            this.bbiDelete.Caption = "X\x00f3a";
            this.bbiDelete.Id = 0;
            this.bbiDelete.Name = "bbiDelete";
            this.bbiDelete.ItemClick += new ItemClickEventHandler(this.bbiDelete_ItemClick);
            this.ppMenu.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiDelete) });
            this.ppMenu.Manager = this.barManager1;
            this.ppMenu.Name = "ppMenu";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.gcList);
            base.Controls.Add(this.barDockControlLeft);
            base.Controls.Add(this.barDockControlRight);
            base.Controls.Add(this.barDockControlBottom);
            base.Controls.Add(this.barDockControlTop);
            base.Name = "xucActivity";
            base.Size = new Size(0x30b, 0x1de);
            this.gcList.EndInit();
            this.gbList.EndInit();
            this.barManager1.EndInit();
            this.ppMenu.EndInit();
            base.ResumeLayout(false);
        }

        public void Save()
        {
            HRM_EMPLOYEE_ACTIVITY hrm_employee_activity = new HRM_EMPLOYEE_ACTIVITY();
            hrm_employee_activity.Delete(this.m_EmployeeCode);
            try
            {
                foreach (DataRow row in (this.gcList.DataSource as DataTable).Rows)
                {
                    if (row != null)
                    {
                        hrm_employee_activity.Insert(Guid.NewGuid(), this.m_EmployeeCode, (row["FromDate"].ToString() != "") ? Convert.ToDateTime(row["FromDate"].ToString()) : DateTime.Now, (row["ToDate"].ToString() != "") ? Convert.ToDateTime(row["ToDate"].ToString()) : DateTime.Now, row["Activity"].ToString(), row["Where"].ToString(), row["Position"].ToString(), row["Description"].ToString());
                    }
                }
            }
            catch
            {
            }
        }
    }
}

